package libronigro;

public class Operazioni {

	public int potenza(int a, int n) {
		if (n < 0)
			throw new IllegalArgumentException("dati errati (>0)");
		if (n == 0)
			return 1;
		return a * potenza(a, n - 1);
	}// potenza

	public int potenzaIT(int a, int n) {
		int p = 1;
		for (int i = 0; i < n; i++)
			p *= a;
		return p;
	}// potenzaIT

	public boolean palindroma(String s) {
		if (s.length() <= 1)
			return true;
		if (s.charAt(0) != s.charAt(s.length() - 1))
			return false;
		return palindroma(s.substring(1, s.length() - 1));
	}// palindroma

	public boolean palindromaIT(String s) {
		int i = 0, j = s.length() - 1;
		while (i <= j) {
			if (s.charAt(i) != s.charAt(j))
				return false;
			i++;
			j++;
		}
		return true;
	}// palindromaIT
	
	public int mcd(int n, int m){
		if(m==0) return n;
		return mcd(m, n%m);
	}//mcd
	
	public int massimo(int[] v, int inf, int sup){
		if(v.length<0) throw new IllegalArgumentException(" ci vogliono dati >0");
		if(inf==sup) return v[inf];
		int med=(inf+sup)/2;
		int m1=massimo(v,inf,med);
		int m2=massimo(v,med+1,sup);
		return (m1>m2)?m1:m2;
	}//massimo

}
